# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/22'
__author__ = 'Just'
__filename__ = 'theme'
"""
from datetime import datetime
from app.model.base import MixinJSONSerializer


class ThemeViewModel(MixinJSONSerializer):
    """单个主题详细信息"""
    def __init__(self, theme, comics):
        self.id = theme.id
        self.title = theme.title
        self.description = theme.description
        self.update_time = datetime.fromtimestamp(theme.update_time)
        self.count = len(comics)
        self.comics = comics
        self._fields = ['id', 'title', 'description', 'update_time', 'count', 'comics']


class ThemeCollection(MixinJSONSerializer):
    """一组主题"""
    def __init__(self):
        self.total = None
        self.themes = []
        self._fields = ['themes', 'total']

    def fill(self, collection):
        """一组"""
        self.themes = [ThemeViewModel(item[0], item[1]) for item in collection]
        self.total = len(self.themes)
